﻿// answer.js
SearchButtonClick = function ()
{
	var $query = $('input:text').val()
	
	$('.resultLabel').html('');
	$('.results').html('');
	if ($query != '')
	{
		$.get('yaproxy.php', 'query=' + $query, function(data) 
		{
			$('.resultLabel').html('Results for: ' + '<b>' + $query + '</b>');
			var obj = jQuery.parseJSON(data);
			var questions = obj.all.questions;
			var html = '';
			$.each(questions , function(questionIndex, question) 
			{
				html += '<div>';
				html += '<p><img src="' + question.UserPhotoURL + '" /><em><a href="'+ question.Link +'" target="_blank">' + question.Subject + '</a></em><br/>';
				html += question.Content + '<br/>';
				html += '</p>';
				html += '</div>';
			});
			$('.results').html(html);
		});
	}
}

$(document).ready(function () 
{
	$('#btnSearch').click(SearchButtonClick);
});